<style>
    .fixed-table-pagination .pagination-detail, .fixed-table-pagination div.pagination {
         margin-top: 0px;
         margin-bottom: 0px;
    }
</style>
<div class="container-fluid">
    <div class="row">
        <div class="panel panel-default" style="margin-bottom: 0px;">
            <div class="panel-heading" style="font-weight: bold">
                <span>家具基本信息</span>
            </div>
            <div class="panel-body">
                <div id="toolbar" style="margin-bottom: 5px;">
                    <div class="form-inline">
                        <button class="btn btn-info btn-sm" onclick="clickSearch()">
                            <span class="glyphicon glyphicon-search" aria-hidden="true"></span>
                            查询
                        </button>
                        <button class="btn btn-primary btn-sm" onclick="clickAdd()">新增</button>
                        <button class="btn btn-warning btn-sm" onclick="clickAlter()">变动</button>
                        <button class="btn btn-danger btn-sm" onclick="clickDeleteAll()">批量删除</button>
                        <button class="btn btn-success btn-sm" onclick="importExcel()">导入Excel</button>
                        <button class="btn btn-success btn-sm" onclick="exportExcel()">导出Excel</button>
                    </div>
                </div>
                <table id="list-table"></table>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        var h = $(window).height();
        $("#list-table").bootstrapTable({
            url:'getFurnList',
            method:'post',
            sidePagination: 'server',
            pagination:true,
            pageSize:20,
            pageList:[10,20,50],
            pageNumber:1,
            height:h - 210,
            columns:[{
                checkbox:true
            },{
                title:'家具编号',
                field:'FURN_NO',
                sortable:true
            },{
                title:'家具名称',
                field:'FURN_NAME',
                sortable:true
            },{
                title:'隶属单位',
                field:'BELONG',
                sortable:true,
            },{
                title:'所在学院',
                field:'COLLEGE',
                sortable:true,
            },{
                title:'使用单位',
                field:'DEPART',
                sortable:true,
            },{
                title:'领用人',
                field:'GET_PERSON',
                sortable:true,
            },{
                title:'状态',
                field:'STATE',
                sortable:true,
            },{
                title:'入账日期',
                field:'ENTER_TIME',
                sortable:true,
            },{
                title:'操作',
                field:'FURN_NO',
                halign:'center',
                align:'center',
                formatter:function (value,rowData,index) {
                    var html1 = "<button class='btn btn-xs btn-default' FURN_NO='" + value + "' onclick='clickDetail(this)' style='margin: 2px;'>查看</button>";
                    var html3 = "<button class='btn btn-xs btn-danger' FURN_NO='" + value + "' onclick='clickDelete(this)' style='margin: 2px;'>删除</button>";
                    return html1 + html3;
                }
            }],
            queryParams:function (params) {
                params.search = $("#search").val();
                return params;
            },
            responseHandler:function (res) {
                console.log(res)
                return res;
            }
        });
    });

    function refreshTable() {
        $("#list-table").bootstrapTable('refresh');
    }

    function clickDetail(obj) {
        var furnNo = $(obj).attr('FURN_NO');
        var h = $(window).height()*0.9;
        var w = $(window).width()*0.9;
        layer.open({
            title:'查看家具',
            area:[w + 'px', h + 'px'],
            type:2,
            content:"{:url('editPage')}?furnNo=" + furnNo
        });
    }

    function clickDelete() {
        layer.confirm('确认删除该家具吗？',{icon:3});
    }

    function clickDeleteAll() {

        var list = $("#list-table").bootstrapTable("getSelections");
        if(list.length < 1){
            layer.alert('请勾选要删除的家具',{icon:2});
            return;
        }

        var idList = [];
        for(var i = 0 ; i < list.length ; i++){
            idList.push(list[i]['FURN_NO']);
        }

        layer.confirm('确认删除选中的家具吗？',{icon:3},function (index) {
            layer.close(index);
            layer.load();
            $.ajax({
                url:"{:url('deleteAll')}",
                data:{list:idList},
                success:function (res) {
                    layer.closeAll('loading');
                    var json = JSON.parse(res);
                    if(json['code'] == '200'){
                        layer.alert(json['msg'],{icon:1},function (index) {
                            layer.close(index);
                            refreshTable();
                        });
                    }
                    else{
                        layer.alert(json['msg'],{icon:2});
                    }
                },
                error:function (res) {
                    layer.closeAll('loading');
                    layer.alert('网络错误',{icon:2});
                }
            });
        });
    }

    function clickAdd() {
        var h = $(window).height()*0.9;
        var w = $(window).width()*0.9;
        layer.open({
            title:'新增家具',
            area:[w + 'px', h + 'px'],
            type:2,
            content:"{:url('addPage')}"
        });
    }

    function clickAlter() {
        var list = $("#list-table").bootstrapTable("getSelections");
        if(list.length < 1){
            layer.alert('请勾选要变动的家具',{icon:2});
            return;
        }
        var idList = '';
        for(var i = 0 ; i < list.length ; i++){
            idList += idList==''?list[i]['FURN_NO']:',' + list[i]['FURN_NO'];
        }

        var h = $(window).height()*0.9;
        var w = $(window).width()*0.9;
        layer.open({
            title:'新增家具变动',
            area:[w + 'px', h + 'px'],
            type:2,
            content:"{:url('addAlterPage')}?idList=" + idList
        });
    }

    function clickSearch() {
        var h = $(window).height()*0.8;
        var w = $(window).width()*0.3;
        if(w > 1200){
            w = 1200;
        }
        layer.open({
            title:'查询--请输入查询条件',
            area:[w + 'px', h + 'px'],
            type:2,
            content:"{:url('searchPage')}"
        });
    }


    function exportExcel() {
        var h = $(window).height()*0.8;
        var w = $(window).width()*0.8;
        if(w > 1200){
            w = 1200;
        }
        layer.open({
            title:'导出',
            area:[w + 'px', h + 'px'],
            type:2,
            content:"{:url('exportExcelPage')}"
        });
    }

    function importExcel() {
        var h = $(window).height()*0.8;
        var w = $(window).width()*0.8;
        if(w > 1200){
            w = 1200;
        }
        layer.open({
            title:'导入',
            area:[w + 'px', h + 'px'],
            type:2,
            content:"{:url('importPage')}",
            end:function () {
                refreshTable();
            }
        });
    }

</script>